package sim;

import java.util.Random;

import sim.input.Mouse;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

/**
 * A base class that is aimed to be used with simulating objects in the game. It
 * contains vectors for position and velocity (Although the latter is optional).
 * 
 * Update code should be placed in the update method, and draw code should be
 * placed in the draw method.
 */
public class Sprite implements Updateable
{
	private Vector2 oldImageSize;
	public Image image;

	/**
	 * The position of the sprite.
	 */
	public Vector2 pos;
	/**
	 * The velocity of the sprite.
	 */
	public Vector2 vel;

	/**
	 * A rectangle that encompasses the entire sprite. Changes on this object
	 * will have no effect.
	 */
	public Rectangle bounds;

	public Sprite(Image image, float x, float y)
	{
		
		pos = new Vector2(x, y);
		vel = new Vector2(x, y);
		this.image = image;

		Random rad = new Random();
		
		bounds = new Rectangle(x, y, image.getWidth(), image.getHeight());

	}
	
	public Sprite(Image image, Vector2 pos, float height, float width)
	{
		this(image, pos.x, pos.y);
		image.setSize(width, height);
	}

	public Sprite(Image image, Vector2 pos)
	{
		this(image, pos.x, pos.y);
	}

	@Override
	public void draw()
	{
		image.draw(pos);

	}

	@Override
	public void update(float timeStep)
	{
		bounds.x = pos.x;
		bounds.y = pos.y;
		
		
		bounds = new Rectangle(pos.x, pos.y, image.getWidth(), image.getHeight());
		
		pos.x += vel.x * timeStep;
		pos.y += vel.y * timeStep;

		if (pos.x + image.getWidth() < 0)
			pos.x = 200;

		if (pos.x > 200)
			pos.x = 0 - image.getWidth();

		if (pos.y + image.getHeight() < 0)
			pos.y = 150;

		if (pos.y > 150)
			pos.y = 0 - image.getHeight();
	}
	
	public boolean isTouched(Camera camera)
	{
		if (Mouse.isTouched())
			if (bounds.contains(Mouse.getPos(camera).x,
					Mouse.getPos(camera).y))
				return true;
			
		return false;
	}
	
	public boolean isPressed(Camera camera)
	{
		if (Mouse.isPressed())
			if (bounds.contains(Mouse.getPos(camera).x,
					Mouse.getPos(camera).y))
				return true;
			
		return false;
	}
}
